<template>
	<uni-popup ref="popupRef" type="center">
		<view class="policy">
			<view class="wrap">
				<view class="kd-main">
					<view class="info">
						<text class="title">登录账号</text>
						<text class="subtitle">手机号快捷登录</text>
					</view>
					<view class="btns">
						<button open-type="getPhoneNumber" @getphonenumber="getPhoneNumber">确认授权</button>
						<button @click="close()">取消登录</button>
					</view>
				</view>
				<view class="close-wrap">
					<view class="iconfont icon-close-circle close" @click="close()"/>
				</view>
			</view>
		</view>
	</uni-popup>
</template>

<script name="MyLogin" setup>
import { defineExpose, ref } from 'vue'
import { useStore } from 'vuex'
const store = useStore()
const popupRef = ref()
function getPhoneNumber (e) {
	console.log(e.detail.code)
	uni.showLoading({
		title: '正在登录...'
	})
	store.dispatch('user/login', {
		code: e.detail.code
	}).then(res => {
		uni.hideLoading()
		store.dispatch('user/getUserInfo')
		uni.showToast({
			title: '登录成功！'
		})
		close()
	}).catch(() => {
		uni.hideLoading()
		close()
	})
}
function open() {
	console.log('open')
	popupRef.value.open()
}
function close() {
	popupRef.value.close()
}
defineExpose({
	open,
	close
})
</script>

<style lang="scss">
@import '@/static/styles/index.scss';
@import '@/static/font-icon/iconfont.css';
.policy {
	display: flex;
	justify-content: center;
	.wrap {
		width: 90vw;
		.top_pic {
			width: 100%;
		}
		.kd-main {
			margin-top: -12rpx;
			background: #fff;
			text-align: center;
			position: relative;
			border-radius: 10rpx;
			overflow: hidden;
			padding-bottom: 30rpx;
			.info {
				padding: 30rpx 0;
				display: flex;
				flex-direction: column;
				background: rgb(0, 98, 255);
				.title {
					font-size: 40rpx;
					color: #fff;
					font-weight: bold;
				}
				.subtitle {
					margin-top: 20rpx;
					color: #fff;
				}
			}
			.kdzc {
				margin-top: 40rpx;
				width: 500rpx;
			}
			.btns {
				margin-top: 30rpx;
				display: flex;
				justify-content: center;
				align-items: center;
				button {
					height: 70rpx;
					background: red;
					padding: 0 30rpx;
					border-radius: 35rpx;
					display: flex;
					align-items: center;
					justify-content: center;
					font-size: 30rpx;
					color: #fff;
				}
				button:nth-child(1) {
					margin-right: 20rpx;
					background: rgb(0, 98, 255);
				}
				button:nth-child(2) {
					background: #CCCCCC;
				}
			}
		}
	}
	.close-wrap {
		display: flex;
		justify-content: center;
		.close {
			color: #fff;
			font-size: 90rpx;
				margin-top: 40rpx;
		}
	}
}

</style>
